﻿using System;
using System.Web;

namespace Clover.BaseAuth
{
    public class DefaultCurrentPermission : ICurrentPermission
    {
        internal static DefaultCurrentPermission _instance { get; set; }
        
        public static DefaultCurrentPermission Default {
            get => _instance ?? new DefaultCurrentPermission();
            set => _instance = value;
        }

        public virtual Enum[] ReadPermissions(string Identity)
        {
            return HttpContext.Current.Session[Identity] as Enum[];
        }

        Enum[] ICurrentPermission.ReadPermissions(string Identity)
        {
            return Default.ReadPermissions(Identity);
        }

        public virtual void SavePermissions(string Identity,Enum[] Permissions)
        {
            HttpContext.Current.Session[Identity] = Permissions;
        }

        void ICurrentPermission.SavePermissions(string Identity,Enum[] Permissions)
        {
            Default.SavePermissions(Identity,Permissions);
        }
    }
}
